#include <rclcpp/rclcpp.hpp>  
#include <rcl_interfaces/msg/set_parameters_result.hpp>

#include <string>  
#include <vector>

using namespace std::placeholders;

class SimpleParameter : public rclcpp::Node
{
public:
  SimpleParameter() : Node("simple_parameter")
  {
    declare_parameter<int>("simple_int_param", 28);
    declare_parameter<std::string>("simple_string_param", "Antonio");
    param_callback_handle_ = add_on_set_parameters_callback(
      std::bind(&SimpleParameter::paramChangeCallback, this, _1));
  }

private:
  OnSetParametersCallbackHandle::SharedPtr param_callback_handle_;

  rcl_interfaces::msg::SetParametersResult paramChangeCallback(const std::vector<rclcpp::Parameter> &parameters)
  {
    rcl_interfaces::msg::SetParametersResult result;
    // 实现参数变化的回调逻辑
    for (const auto &param : parameters)
    {
      if (param.get_name() == "simple_int_param" && 
        param.get_type() == rclcpp::ParameterType::PARAMETER_INTEGER)
      {
        RCLCPP_INFO_STREAM(this->get_logger(), "simple_int_param changed to " << param.as_int());
        result.successful = true;
      }
      else if (param.get_name() == "simple_string_param" && 
        param.get_type() == rclcpp::ParameterType::PARAMETER_STRING)
      {
        RCLCPP_INFO(this->get_logger(), "simple_string_param changed to %s", param.as_string().c_str());
        result.successful = true;
      }
      else 
      {
        RCLCPP_INFO(this->get_logger(), "Parameter changed failed");
        result.successful = true;
      }
    }
    return result;
  }
};

int main(int argc, char * argv[])
{
  rclcpp::init(argc, argv);
  auto node = std::make_shared<SimpleParameter>();
  rclcpp::spin(node);
  rclcpp::shutdown();

  return 0;
}